<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .item {
      width: 400px;
      height: 400px;
      background-color: yellow;
      margin: 10px;
    }
  </style>
</head>

<body>
  <div class="item">0</div>
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
  <div class="item">6</div>
  <script>
    let items = document.querySelectorAll('.item')
    let lastItem = items[3]
    console.log(lastItem.offsetTop);
    document.documentElement.addEventListener('click', (e) => {
      console.log(e.target.offsetTop, '-----');

    })
    window.addEventListener('scroll', debounce(getOffset, 500))
    function debounce(fn, delay) {
      let timer = null
      return function (...args) {
        let _this = this
        if (timer) clearTimeout(timer)
        timer = setTimeout(() => {
          fn.apply(_this, args)
          timer = null
        }, delay)
      }
    }
    function getOffset() {
      console.log(items[3].offsetTop, '============'); 
    }
  </script>
</body>

</html>